<?php

use yii\helpers\Html;
use yii\grid\GridView;
use kartik\file\FileInput;


$this->title = '人员护照审核';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="customer-check-index">

    <h2 class="page-header"><?= Html::encode($this->title) ?>
        <div class="pull-right" style="display: inline-block;">
            <?= Html::a('创建人员', ['create'], ['class' => 'btn btn-success']) ?>
            <div style="display: inline-block;">
            <?php echo FileInput::widget([
                  'language' => 'zh',
                  'name' => 'excel',
                  'id' => 'file-upload',
                  'pluginOptions' => [
                      'uploadUrl' => "/cruise/check/import-cut",
                      'uploadExtraData' => [
                          '_csrf' => Yii::$app->getRequest()->getCsrfToken(),
                      ],
                      'showPreview' => false,
                      'showCaption' => false,
                      'showRemove' => false,
                      'showUpload' => false,
                      'uploadAsync'=> true,
                      'maxFileCount' => 1,
                      'browseClass' => 'btn btn-warning',
                      'browseIcon' => '',
                      'browseLabel' => '导入人员',
                      'fileTypeSettings' => [],
                  ],
                  'options' => ['accept' => '', 'multiple'=>false],
                  ]);?>
            </div>  
            <a href="/download/template1.xlsx" style="font-size: 14px;text-decoration:underline;">下载导入人员模板</a>   
        </div>
    </h2>
    

    <p>
        <?php  echo $this->render('_search', ['model' => $searchModel]); ?>
    </p>
   

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        //'filterModel' => $searchModel,
        'layout'  =>  "{items}\n{pager}",
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            //'id',
            [
                'label' => '姓名',
                'format'=>'raw',
                'value'=>function ($model) {
                    return $model->first_name.$model->last_name;
                },
            ],
           [
                'attribute' => 'gender',
                'filter' =>  Yii::$app->params['gender'],
                'value' => function ($model) {
                    return isset(Yii::$app->params['gender'][$model->gender])?Yii::$app->params['gender'][$model->gender]:'';
                },
                'format' => 'raw',
            ],
            //'pinyin',
            //'gender',
            //'birthday',
            //'country',
            'passport',
            'group',
            //'passport_add',
            //'passport_date',
            //'passport_grant',
            //'passport_img',
            //'native',
            //'phone',
            //'remark',
            //'name',
            //'passport_check',
            [
                'attribute' => 'passport_check',
                'filter' =>  Yii::$app->params['passport_check'],
                'value' => function ($model) {
                    return isset(Yii::$app->params['passport_check'][$model->passport_check])?Yii::$app->params['passport_check'][$model->passport_check]:'';
                },
                'format' => 'raw',
            ],
            [
                'attribute' => 'status',
                'filter' =>  Yii::$app->params['status'],
                'value' => function ($model) {
                    return Yii::$app->params['status'][$model->status];
                },
                'format' => 'raw',
            ],
            //'user_id',
            //'created_at',
            //'updated_at',

            ['class' => 'yii\grid\ActionColumn','template' =>"{view} {update}"],
        ],
    ]); ?>
</div>


<?=  yii\web\View::registerJsFile("/js/layer/layer.js",['depends' => 'app\assets\AppAsset']) ?>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">

  $('#file-upload').on('filebatchselected', function(event, files) {
      $(this).fileinput("upload");
  });

  $('#file-upload').on('fileuploaded', function(event, data, previewId, index) {
      var response = data.response;
      if(response.code == 'error'){
          layer.msg(response.message,{time: 5000},function(){});
          setTimeout("window.location.reload()",5000);
          return false;
      }else if(response.code == 'ok'){
          layer.msg(response.message);
          window.location.reload();
          return false;
      }
  });


</script>
<?php app\components\JsBlock::end() ?>  